home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
comm
/
mail
/
Mutt089src.lha
/
Mutt-0.89i-AMIGA
/
src
/
init.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-28
|
34KB
|
1,517 lines
/*
* Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_regex.h"
#ifdef _PGPPATH
#include "pgp.h"
#endif
#include "mx.h"
#include "init.h"
#include "mailbox.h"
#include <pwd.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>
#include <errno.h>
#include <sys/wait.h>
#ifdef AMIGA
# include "getenv.c" /* getenv of ixemul.library is buggy */
#endif
void set_quadoption (int opt, int flag)
{
QuadOptions &= ~(0x3 << (2 * opt)); /* first clear the bits */
QuadOptions |= (flag & 0x3) << (2 * opt); /* now set them */
}
int quadoption (int opt)
{
return ((QuadOptions >> (opt * 2)) & 0x3);
}
int query_quadoption (int opt, const char *prompt)
{
int v = quadoption (opt);
switch (v)
{
case M_YES:
case M_NO:
return (v);
default:
v = mutt_yesorno (prompt, (v == M_ASKYES));
CLEARLINE (LINES - 1);
return (v);
}
/* not reached */
}
/* given the variable ``s'', return the index into the rc_vars array which
* matches, or -1 if the variable is not found.
*/
int mutt_option_index (char *s)
{
int i;
for (i=0; MuttVars[i].option; i++)
if (strcmp (s, MuttVars[i].option) == 0)
return (i);
return (-1);
}
void mutt_add_to_list (LIST **list, const char *s)
{
LIST *t, *last = NULL;
char buf[SHORT_STRING];
char expn[LONG_STRING];
do
{
s = mutt_extract_token (buf, sizeof (buf), s, expn, sizeof (expn), 0);
/* check to make sure the item is not already on this list */
for (last = *list; last; last = last->next)
{
if (strcasecmp (buf, last->data) == 0)
{
/* already on the list, so just ignore it */
last = NULL;
break;
}
if (!last->next)
break;
}
if (!*list || last)
{
t = (LIST *) safe_calloc (1, sizeof (LIST));
t->data = safe_strdup (buf);
if (last)
{
last->next = t;
last = last->next;
}
else
*list = last = t;
}
}
while (s);
}
static void remove_from_list (LIST **l, const char *s)
{
LIST *p, *last = NULL;
char buf[SHORT_STRING];
char expn[LONG_STRING];
do
{
s = mutt_extract_token (buf, sizeof (buf), s, expn, sizeof (expn), 0);
if (strcmp ("*", buf) == 0)
mutt_free_list (l); /* ``unCMD *'' means delete all current entries */
else
{
p = *l;
last = NULL;
while (p)
{
if (strcasecmp (buf, p->data) == 0)
{
safe_free ((void **) &p->data);
if (last)
last->next = p->next;
else
(*l) = p->next;
safe_free ((void **) &p);
}
else
{
last = p;
p = p->next;
}
}
}
}
while (s);
}
static int parse_unignore (const char *s, void *data, char *err, size_t errlen)
{
mutt_add_to_list (&UnIgnore, s);
remove_from_list (&Ignore, s);
return 0;
}
static int parse_ignore (const char *s, void *data, char *err, size_t errlen)
{
mutt_add_to_list (&Ignore, s);
remove_from_list (&UnIgnore, s);
return 0;
}
static int parse_list (const char *s, void *data, char *err, size_t errlen)
{
mutt_add_to_list ((LIST **) data, s);
return 0;
}
static int
parse_unlist (const char *s, void *data, char *err, size_t errlen)
{
remove_from_list ((LIST **) data, s);
return 0;
}
static int parse_unalias (const char *s, void *data, char *err, size_t errlen)
{
ALIAS *tmp, *last = NULL;
char buf[SHORT_STRING];
char expn[LONG_STRING];
do
{
s = mutt_extract_token (buf, sizeof (buf), s, expn, sizeof (expn), 0);
tmp = Aliases;
for (tmp = Aliases; tmp; tmp = tmp->next)
{
if (strcasecmp (buf, tmp->name) == 0)
{
if (last)
last->next = tmp->next;
else
Aliases = tmp->next;
tmp->next = NULL;
mutt_free_alias (&tmp);
break;
}
last = tmp;
}
}
while (s);
return 0;
}
static int parse_alias (const char *s, void *data, char *errmsg, size_t errlen)
{
ALIAS *tmp = Aliases;
ALIAS *last = NULL;
const char *p;
size_t len;
char buf[HUGE_STRING];
char expn[LONG_STRING];
if ((p = strpbrk (s, " \t")) == NULL)
{
strfcpy (errmsg, "alias has no address", errlen);
return (-1);
}
len = p - s;
/* check to see if an alias with this name already exists */
for (; tmp; tmp = tmp->next)
{
if (strncasecmp (tmp->name, s, len) == 0 && *(tmp->name + len) == 0)
break;
last = tmp;
}
if (!tmp)
{
/* create a new alias */
tmp = (ALIAS *) safe_calloc (1, sizeof (ALIAS));
tmp->name = safe_malloc (len + 1);
memcpy (tmp->name, s, len);
tmp->name[len] = 0;
}
else
{
/* override the previous value */
mutt_free_address (&tmp->addr);
}
mutt_extract_token (buf, sizeof (buf), p, expn, sizeof (expn), M_QUOTE | M_SPACE);
rfc822_parse_adrlist (&tmp->addr, buf, "@");
if (last)
last->next = tmp;
else
Aliases = tmp;
return 0;
}
static int parse_unmy_hdr (const char *s, void *data, char *err, size_t errlen)
{
LIST *last = NULL;
LIST *tmp = UserHeader;
LIST *ptr;
char buf[SHORT_STRING];
char expn[LONG_STRING];
size_t l;
do
{
s = mutt_extract_token (buf, sizeof (buf), s, expn, sizeof (expn), 0);
if (strcmp ("*", buf) == 0)
mutt_free_list (&UserHeader);
else
{
tmp = UserHeader;
last = NULL;
l = strlen (buf);
if (buf[l - 1] == ':')
l--;
while (tmp)
{
if (strncasecmp (buf, tmp->data, l) == 0 && tmp->data[l] == ':')
{
ptr = tmp;
if (last)
last->next = tmp->next;
else
UserHeader = tmp->next;
tmp = tmp->next;
ptr->next = NULL;
mutt_free_list (&ptr);
}
else
{
last = tmp;
tmp = tmp->next;
}
}
}
}
while (s);
return 0;
}
static int parse_my_hdr (const char *s, void *data, char *errmsg, size_t errlen)
{
LIST *tmp;
size_t keylen;
char *p;
char buf[LONG_STRING];
char expn[LONG_STRING];
mutt_extract_token (buf, sizeof (buf), s, expn, sizeof (expn), M_SPACE | M_QUOTE);
if ((p = strpbrk (buf, ": \t")) == NULL || *p != ':')
{
strfcpy (errmsg, "invalid header field", errlen);
return (-1);
}
keylen = p - buf + 1;
p++;
SKIPWS (p);
if (!*p)
{
snprintf (errmsg, errlen, "ignoring empty header field: %s", s);
return (-1);
}
if (UserHeader)
{
for (tmp = UserHeader; ; tmp = tmp->next)
{
/* see if there is already a field by this name */
if (strncasecmp (buf, tmp->data, keylen) == 0)
{
/* replace the old value */
safe_free ((void **) &tmp->data);
tmp->data = safe_strdup (buf);
return 0;
}
if (!tmp->next)
break;
}
tmp->next = mutt_new_list ();
tmp = tmp->next;
}
else
{
tmp = mutt_new_list ();
UserHeader = tmp;
}
tmp->data = safe_strdup (buf);
return 0;
}
static int parse_sort (short *val, const char *s, char *err, size_t errlen)
{
int i, flags = 0;
if (strncmp ("reverse-", s, 8) == 0)
{
s += 8;
flags = SORT_REVERSE;
}
if (strncmp ("last-", s, 5) == 0)
{
s += 5;
flags |= SORT_LAST;
}
if ((i = mutt_getvaluebyname (s, SortMethods)) == -1)
{
snprintf (err, errlen, "%s: unknown sorting method", s);
return (-1);
}
*val = i | flags;
return 0;
}
/* flags
* M_EQUAL '=' is a terminator
* M_CONDENSE condense ^(char) runs
* M_SPACE don't treat whitespace as a terminator
* M_QUOTE don't interpret quotes
* M_BACKSLASH don't interpret the `\'